//
//  YHYBaseModel.m
//  Relax
//
//  Created by yanghuiyan on 16/4/18.
//  Copyright © 2016年 yanghuiyan. All rights reserved.
//

#import "YHYBaseModel.h"

@implementation YHYBaseModel

- (void)setValue:(id)value forKey:(NSString *)key {
    
    [super setValue:value forKey:key];
    
//    if ([key isEqualToString:@"name"]) {
//        self.name = [NSString stringWithFormat:@"favorite%@", value];
//    }
    
}

// 当model的属性没有字典的key值相匹配时
- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
//    [super setValue:value forUndefinedKey:key];
    
}



- (id)valueForUndefinedKey:(NSString *)key {
    
    return nil;
    
}

// 重写初始化方法
- (instancetype)initWithDataSource:(NSDictionary *)dataSource {
    
    self = [super init];
    
    if (self) {
        
        [self setValuesForKeysWithDictionary:dataSource];
        
    }
    
    return self;
    
}

// 遍历构造器
+ (instancetype)modelWithDictionary:(NSDictionary *)dictionary {
    
//    YHYBaseModel *model = [[YHYBaseModel alloc] initWithDataSource:dictionary];
//    
//    return model;
    
    
    /**
     编译时NSString 运行时NSData
     */
//    NSString *str = [[NSData alloc] init];
    
    return [[self alloc]initWithDataSource:dictionary];
    
}

@end
